package com.homework.service;

import java.sql.SQLException;

import com.homework.bean.CourseBean;
import com.homework.bean.PageInfoBean;
import com.homework.bean.UserBean;
import com.homework.bean.UserListBean;
import com.homework.dao.UserDao;

public class UserService {

	private static UserService userService = null;
	private UserDao userDao;

	public UserService() {
		this.userDao = UserDao.getInstance();
	}

	public static UserService getInstance() {
		if (userService == null) {
			userService = new UserService();
		}
		return userService;
	}

	// 登陆
	public int login(UserBean userBean) throws SQLException {
		return userDao.login(userBean);
	}

	// 注册业务
	public int regist(UserBean userBean) throws SQLException {
		return userDao.regist(userBean);
	}

	// 验证用户名是否重复
	public boolean usernameCheck(String username) throws SQLException {
		return userDao.usernameCheck(username);
	}

	// 修改密码
	public boolean changePassword(Object userId, String newPassword) {
		return userDao.changePassword(userId, newPassword);
	}

	public boolean passwordCheck(Object userId, String oldPassword) {
		return userDao.passwordCheck(userId, oldPassword);
	}

	public boolean updateLoginTime(int userId) {
		return userDao.updateLoginTime(userId);
		
	}

	public boolean updateLoginIp(int userId) {
		return userDao.updateLoginIp(userId);
		
	}

	public int findUserIdByUsername(String username) {
		return userDao.findUserIdByUsername(username);
	}

	public int findRoleIdByUsername(String username) {
		return userDao.findRoleIdByUsername(username);
	}
	
	// 学生列表
	public UserListBean studentShow(CourseBean courseBean,PageInfoBean pageInfoBean) throws SQLException{
		return userDao.studentShow(courseBean, pageInfoBean);
	}
	
	//学生查询
	public UserListBean studentQuery(CourseBean courseBean,PageInfoBean pageInfoBean,UserBean userBean) throws SQLException{
		return userDao.studentQuery(courseBean, pageInfoBean,userBean);
	}

	//修改用户状态
	public boolean updateUserStatus(Object userId,int userStatus) {
		return userDao.updateUserStatus(userId,userStatus);
	}

	//获取用户信息
	public UserBean getUserInfo(String userId){
		return userDao.getUserInfo(userId);
	}
	
	//保存用户信息
	public boolean setUserInfo(UserBean userBean){
		return userDao.setUserInfo(userBean);
	}
	
	public int getIdbyName(String name){
		return userDao.getIdbyName(name);
	}

	// 用户查询（管理员）
	public UserListBean userQuery(PageInfoBean pageInfoBean, UserBean userBean)
			throws SQLException {
		return userDao.userQuery(pageInfoBean, userBean);
	}

	// 用户列表（管理员）
	public UserListBean userAuditing(PageInfoBean pageInfoBean)
			throws SQLException {
		return userDao.userAuditing(pageInfoBean);
	}

	// 用户启用或通过审核
	public void userPass(UserBean userBean) {
		userDao.userPass(userBean);
	}

	// 禁用用户
	public void userForbid(UserBean userBean) {
		userDao.userForbid(userBean);
	}
}
